<template>
  <div class="event-status-tracking">
    <!-- 事件概览 -->
    <div class="event-overview">
      <div class="overview-header">
        <div class="event-title">{{ currentEvent.eventName }}</div>
        <el-tag :type="getStatusType(currentEvent.status)" size="medium">
          {{ currentEvent.status }}
        </el-tag>
      </div>
      
      <div class="event-info">
        <div class="info-item">
          <i class="el-icon-s-flag"></i>
          <span>{{ currentEvent.eventType }}</span>
        </div>
        <div class="info-item">
          <i class="el-icon-time"></i>
          <span>{{ currentEvent.occurTime }}</span>
        </div>
        <div class="info-item">
          <i class="el-icon-location"></i>
          <span>{{ currentEvent.location }}</span>
        </div>
      </div>

      <div class="event-stats">
        <div class="stat-card">
          <div class="stat-icon" style="background: #409EFF;">
            <i class="el-icon-user"></i>
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ currentEvent.totalCases }}</div>
            <div class="stat-label">累计病例</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon" style="background: #E6A23C;">
            <i class="el-icon-warning"></i>
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ currentEvent.treatmentCount }}</div>
            <div class="stat-label">在治人数</div>
          </div>
        </div>

        <div class="stat-card">
          <div class="stat-icon" style="background: #67C23A;">
            <i class="el-icon-success"></i>
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ currentEvent.curedCount }}</div>
            <div class="stat-label">治愈人数</div>
          </div>
        </div>

        <div class="stat-card">
          <div class="stat-icon" style="background: #F56C6C;">
            <i class="el-icon-close"></i>
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ currentEvent.deathCount }}</div>
            <div class="stat-label">死亡人数</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 状态时间轴 -->
    <div class="timeline-section">
      <div class="section-header">
        <i class="el-icon-time"></i>
        <span>处理进展时间轴</span>
      </div>
      
      <div class="timeline-list">
        <div 
          v-for="(item, index) in timeline" 
          :key="item.id"
          class="timeline-item"
          :class="item.status"
        >
          <div class="timeline-node">
            <div class="node-dot" :class="item.status"></div>
            <div v-if="index < timeline.length - 1" class="node-line"></div>
          </div>
          
          <div class="timeline-content">
            <div class="content-header">
              <div class="content-title">{{ item.title }}</div>
              <div class="content-time">{{ item.time }}</div>
            </div>
            
            <div class="content-desc">{{ item.description }}</div>
            
            <div v-if="item.details && item.details.length > 0" class="content-details">
              <div 
                v-for="detail in item.details" 
                :key="detail.label"
                class="detail-item"
              >
                <span class="detail-label">{{ detail.label }}：</span>
                <span class="detail-value">{{ detail.value }}</span>
              </div>
            </div>
            
            <div v-if="item.reporter" class="content-footer">
              <i class="el-icon-user"></i>
              <span>{{ item.reporter }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 处理状态列表 -->
    <div class="status-section">
      <div class="section-header">
        <i class="el-icon-s-check"></i>
        <span>处理状态标记</span>
      </div>
      
      <div class="status-list">
        <div 
          v-for="status in statusList" 
          :key="status.value"
          class="status-item"
          :class="{ active: status.value === currentEvent.status }"
        >
          <div class="status-icon" :style="{ background: status.color }">
            <i :class="status.icon"></i>
          </div>
          <div class="status-info">
            <div class="status-name">{{ status.label }}</div>
            <div class="status-desc">{{ status.description }}</div>
          </div>
          <div v-if="status.value === currentEvent.status" class="status-badge">
            <i class="el-icon-check"></i>
          </div>
        </div>
      </div>
    </div>

    <!-- 快速筛选 -->
    <div class="filter-section">
      <div class="section-header">
        <i class="el-icon-s-grid"></i>
        <span>事件列表</span>
      </div>
      
      <div class="filter-tabs">
        <div 
          v-for="tab in filterTabs" 
          :key="tab.value"
          class="filter-tab"
          :class="{ active: activeFilter === tab.value }"
          @click="activeFilter = tab.value; filterEvents()"
        >
          <span class="tab-label">{{ tab.label }}</span>
          <span class="tab-count">{{ tab.count }}</span>
        </div>
      </div>
      
      <div class="event-list">
        <div 
          v-for="event in filteredEvents" 
          :key="event.id"
          class="event-item"
          :class="{ active: event.id === currentEvent.id }"
          @click="switchEvent(event)"
        >
          <div class="event-header">
            <div class="event-name">{{ event.eventName }}</div>
            <el-tag :type="getStatusType(event.status)" size="mini">
              {{ event.status }}
            </el-tag>
          </div>
          
          <div class="event-meta">
            <span class="meta-item">
              <i class="el-icon-time"></i>
              {{ event.occurTime }}
            </span>
            <span class="meta-item">
              <i class="el-icon-location"></i>
              {{ event.location }}
            </span>
          </div>
          
          <div class="event-progress">
            <div class="progress-bar">
              <div 
                class="progress-fill" 
                :style="{ width: event.progress + '%' }"
              ></div>
            </div>
            <span class="progress-text">{{ event.progress }}%</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getEventTracking, getEventList } from './service';

export default {
  name: 'EventStatusTracking',
  
  data() {
    return {
      currentEvent: {
        id: 1,
        eventName: '某市突发急性传染病疫情',
        eventType: '传染病疫情',
        occurTime: '2024-11-01 08:30',
        location: '某市东城区',
        status: '持续处理中',
        totalCases: 100,
        treatmentCount: 20,
        curedCount: 75,
        deathCount: 5
      },
      
      timeline: [
        {
          id: 1,
          title: '事件初次报告',
          time: '2024-11-01 09:00',
          description: '接到群众报告，多人出现发热、咳嗽等症状',
          status: 'completed',
          details: [
            { label: '涉及人数', value: '50人' },
            { label: '初步诊断', value: '疑似传染病' }
          ],
          reporter: '卫生监督员陈主任'
        },
        {
          id: 2,
          title: '应急响应启动',
          time: '2024-11-01 10:30',
          description: '启动突发公共卫生事件应急预案，成立应急指挥部',
          status: 'completed',
          details: [
            { label: '响应级别', value: '二级' },
            { label: '调配人员', value: '30人' }
          ],
          reporter: '应急指挥部'
        },
        {
          id: 3,
          title: '现场流行病学调查',
          time: '2024-11-02 08:00',
          description: '组织专家开展现场流行病学调查，采集样本送检',
          status: 'completed',
          details: [
            { label: '调查人员', value: '15人' },
            { label: '采集样本', value: '80份' }
          ],
          reporter: '疾控中心调查组'
        },
        {
          id: 4,
          title: '病原体确认',
          time: '2024-11-03 14:00',
          description: '实验室检测结果确认病原体，制定针对性防控方案',
          status: 'completed',
          details: [
            { label: '病原体', value: '甲型流感病毒' },
            { label: '确诊病例', value: '75例' }
          ],
          reporter: '检验科主任'
        },
        {
          id: 5,
          title: '全面防控措施实施',
          time: '2024-11-04 08:00',
          description: '实施隔离治疗、密接追踪、环境消杀等综合防控措施',
          status: 'processing',
          details: [
            { label: '隔离人数', value: '100人' },
            { label: '密接追踪', value: '150人' },
            { label: '消杀面积', value: '5000㎡' }
          ],
          reporter: '防控工作组'
        },
        {
          id: 6,
          title: '疫情趋势分析',
          time: '2024-11-05 16:00',
          description: '分析疫情发展趋势，调整防控策略',
          status: 'processing',
          details: [
            { label: '新增病例', value: '5例' },
            { label: '治愈出院', value: '45例' },
            { label: '疫情趋势', value: '逐步控制' }
          ],
          reporter: '专家组'
        },
        {
          id: 7,
          title: '持续监测观察',
          time: '2024-11-06 当前',
          description: '继续加强监测，巩固防控成果',
          status: 'current',
          details: [
            { label: '在治人数', value: '20人' },
            { label: '观察人数', value: '30人' }
          ],
          reporter: '监测组'
        }
      ],
      
      statusList: [
        {
          value: '初步处置',
          label: '初步处置',
          description: '事件初步报告，开始应急响应',
          color: '#909399',
          icon: 'el-icon-info'
        },
        {
          value: '持续处理中',
          label: '持续处理中',
          description: '正在积极采取措施处理中',
          color: '#E6A23C',
          icon: 'el-icon-loading'
        },
        {
          value: '基本控制',
          label: '基本控制',
          description: '疫情得到基本控制',
          color: '#409EFF',
          icon: 'el-icon-s-flag'
        },
        {
          value: '完全控制',
          label: '完全控制',
          description: '疫情已完全控制',
          color: '#67C23A',
          icon: 'el-icon-circle-check'
        },
        {
          value: '后续观察',
          label: '后续观察',
          description: '进入后续观察期',
          color: '#67C23A',
          icon: 'el-icon-view'
        }
      ],
      
      filterTabs: [
        { value: 'all', label: '全部', count: 8 },
        { value: 'processing', label: '处理中', count: 3 },
        { value: 'controlled', label: '已控制', count: 5 }
      ],
      
      activeFilter: 'all',
      
      eventList: [],
      filteredEvents: []
    };
  },

  methods: {
    getStatusType(status) {
      const typeMap = {
        '初步处置': 'info',
        '持续处理中': 'warning',
        '基本控制': 'primary',
        '完全控制': 'success',
        '后续观察': 'success'
      };
      return typeMap[status] || 'info';
    },

    filterEvents() {
      if (this.activeFilter === 'all') {
        this.filteredEvents = this.eventList;
      } else if (this.activeFilter === 'processing') {
        this.filteredEvents = this.eventList.filter(e => 
          e.status === '初步处置' || e.status === '持续处理中'
        );
      } else if (this.activeFilter === 'controlled') {
        this.filteredEvents = this.eventList.filter(e => 
          e.status === '基本控制' || e.status === '完全控制' || e.status === '后续观察'
        );
      }
    },

    switchEvent(event) {
      this.currentEvent = event;
      this.loadEventTracking(event.id);
    },

    loadEventTracking(eventId) {
      const loading = this.$loading({
        lock: true,
        text: '加载中...',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      getEventTracking(eventId)
        .then(data => {
          loading.close();
          this.timeline = data.timeline;
        })
        .catch(error => {
          loading.close();
          console.error('加载跟踪信息失败', error);
        });
    },

    loadEventList() {
      getEventList().then(data => {
        this.eventList = data;
        this.filteredEvents = data;
      }).catch(error => {
        console.error('加载事件列表失败', error);
      });
    }
  },

  mounted() {
    this.loadEventList();
  }
};
</script>

<style scoped>
.event-status-tracking {
  background: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* 事件概览 */
.event-overview {
  background: white;
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.overview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.event-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  flex: 1;
  margin-right: 10px;
}

.event-info {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-bottom: 15px;
}

.info-item {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: #666;
}

.info-item i {
  margin-right: 5px;
  color: #409EFF;
}

.event-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 12px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-icon i {
  font-size: 20px;
  color: white;
}

.stat-info {
  text-align: center;
}

.stat-value {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 3px;
}

.stat-label {
  font-size: 11px;
  color: #999;
}

/* 时间轴 */
.timeline-section {
  background: white;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.section-header {
  display: flex;
  align-items: center;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 16px;
  font-weight: 600;
}

.section-header i {
  font-size: 20px;
  margin-right: 8px;
}

.timeline-list {
  padding: 20px 15px;
}

.timeline-item {
  display: flex;
  position: relative;
}

.timeline-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-right: 15px;
  flex-shrink: 0;
}

.node-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ddd;
  border: 3px solid white;
  box-shadow: 0 0 0 2px #ddd;
  flex-shrink: 0;
}

.node-dot.completed {
  background: #67C23A;
  box-shadow: 0 0 0 2px #67C23A;
}

.node-dot.processing {
  background: #E6A23C;
  box-shadow: 0 0 0 2px #E6A23C;
}

.node-dot.current {
  background: #409EFF;
  box-shadow: 0 0 0 2px #409EFF;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

.node-line {
  width: 2px;
  flex: 1;
  background: #e4e7ed;
  margin: 5px 0;
}

.timeline-content {
  flex: 1;
  padding-bottom: 25px;
}

.timeline-item:last-child .timeline-content {
  padding-bottom: 0;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.content-title {
  font-size: 15px;
  font-weight: 600;
  color: #333;
}

.content-time {
  font-size: 12px;
  color: #999;
}

.content-desc {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  margin-bottom: 10px;
}

.content-details {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.detail-item {
  font-size: 12px;
  color: #666;
  margin-bottom: 5px;
}

.detail-item:last-child {
  margin-bottom: 0;
}

.detail-label {
  color: #999;
}

.detail-value {
  color: #333;
  font-weight: 500;
}

.content-footer {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #999;
}

.content-footer i {
  margin-right: 5px;
}

/* 状态列表 */
.status-section {
  background: white;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.status-list {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-item {
  display: flex;
  align-items: center;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: all 0.3s;
}

.status-item.active {
  background: #e7f4ff;
  border-color: #409EFF;
}

.status-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.status-icon i {
  font-size: 20px;
  color: white;
}

.status-info {
  flex: 1;
}

.status-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 3px;
}

.status-desc {
  font-size: 12px;
  color: #999;
}

.status-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #409EFF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-badge i {
  font-size: 14px;
  color: white;
}

/* 事件筛选 */
.filter-section {
  background: white;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.filter-tabs {
  display: flex;
  padding: 15px 15px 0 15px;
  border-bottom: 1px solid #e4e7ed;
}

.filter-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  cursor: pointer;
  position: relative;
  transition: all 0.3s;
}

.filter-tab.active {
  color: #409EFF;
}

.filter-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: #409EFF;
}

.tab-label {
  font-size: 14px;
  margin-right: 5px;
}

.tab-count {
  font-size: 12px;
  color: #999;
}

.filter-tab.active .tab-count {
  color: #409EFF;
}

.event-list {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
}

.event-item {
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.event-item.active {
  background: #e7f4ff;
  border-color: #409EFF;
}

.event-item:active {
  transform: scale(0.98);
}

.event-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.event-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  flex: 1;
  margin-right: 10px;
}

.event-meta {
  display: flex;
  gap: 15px;
  margin-bottom: 10px;
}

.meta-item {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #999;
}

.meta-item i {
  margin-right: 5px;
  color: #409EFF;
}

.event-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: #e4e7ed;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #409EFF 0%, #67C23A 100%);
  transition: width 0.3s;
}

.progress-text {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}
</style>

